<?php
//the example of inserting data with variable from HTML form
//input.php

//get values from POST
	$structureName=$_POST['structureName'];        
	$structureDesc=$_POST['structureDesc'];    

        $structureAddress=$_POST['structureAddress'];    
        $surveyorName=$_POST['surveyorName'];    
        $phoneNumber=$_POST['phoneNumber'];    

        $structureOwned=$_POST['structureOwned'];    
        $yearBuilt=$_POST['yearBuilt'];    
        $buildDuration=$_POST['buildDuration'];    
        $builder=$_POST['builder'];    

        $steelWalls=$_POST['steelWalls'];    
        $nFloors=$_POST['nFloors'];    
        $roofType=$_POST['roofType'];    
        $nChildren=$_POST['nChildren'];    
        $nAdults=$_POST['nAdults'];

$photoFrontName = "photoFront_".date('m-d-Y-His').".jpg";
$photoFrontPath = "HIS_PHOTOS/" . $photoFrontName;

$photoRightName	= "photoRight_".date('m-d-Y-His').".jpg";
$photoRightPath	= "HIS_PHOTOS/"	. $photoRightName;

$photoBackName	= "photoBack_".date('m-d-Y-His').".jpg";
$photoBackPath	= "HIS_PHOTOS/"	. $photoBackName;

$photoLeftName	= "photoLeft_".date('m-d-Y-His').".jpg";
$photoLeftPath	= "HIS_PHOTOS/"	. $photoLeftName;

//$target_path = "HIS_PHOTOS/";
//$target_path = $target_path . basename( $_FILES['photoFront']['name']); 

  if ($_FILES["photoFront"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["photoFront"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["photoFront"]["name"] . "<br>";
    echo "Type: " . $_FILES["photoFront"]["type"] . "<br>";
    echo "Size: " . ($_FILES["photoFront"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["photoFront"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["photoFront"]["name"]))
      {
      echo $_FILES["photoFront"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["photoFront"]["tmp_name"],
      "upload/" . $_FILES["photoFront"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["photoFront"]["name"];
      }
    }

mysql_connect("129.74.153.54","HA_User","hag") or die (mysql_error());//databas$
mysql_select_db('HA_database') or die (mysql_error());

$structure = "INSERT INTO structures 
			(structureName, structureDesc, structureAddress, surveyorName, phoneNumber, structureOwned, 
			yearBuilt, buildDuration, builder, steelWalls, nFloors, roofType, nChildren, nAdults, photoFront,
			photoRight, photoBack, photoLeft)
		VALUES
                        ('$structureName', '$structureDesc', '$structureAddress', '$surveyorName', '$phoneNumber', '$structureOwned',
			'$yearBuilt', '$buildDuration', '$builder', '$steelWalls', '$nFloors', '$roofType', '$nChildren', '$nAdults', '$photoFrontPath',
			'$photoRightPath', '$photoBackPath', '$photoLeftPath'
                        )";


$result = mysql_query($structure);	//structure added executes
if($result){
	echo("<br>Structure add succeed");
	//header("Location:test.php");
} else{
	echo("<br> Structure add failed");
}

mysql_close();

?>

